import java.util.ArrayList;
import java.util.List;

class Flattener {


    <T extends Object> List<T> flatten(final List<T> two) {
        List<T> results = new ArrayList<>();
        append(results, two);

        return results;
    }

    private <T extends Object> void append(List<T> results, Object obj) {
        if (obj instanceof List) {
            for (Object o : (List) obj) {
                append(results, o);
            }
        } else {
            if (obj != null) results.add((T) obj);
        }
    }
}